package com.ruipengkj.commons.util.barcode;

import java.awt.Font;
import java.awt.Image;

import com.barcodelib.barcode.Linear;

public class CODE128BarCodeBean {

	
	public static  Image getCodeBeanImage(String str){
		Linear barcode = new Linear();
		barcode.setType(Linear.CODE128);
		// barcode data to encode
		barcode.setData(str);
//		barcode.setTextFont(barcode.getTextFont().deriveFont(30));
		// unit of measure for X, Y, LeftMargin, RightMargin, TopMargin,
		// BottomMargin
		barcode.setUOM(Linear.UOM_PIXEL);
		// barcode module width in pixel
		barcode.setX(3f);
		// barcode module height in pixel
		barcode.setY(75f);

		barcode.setLeftMargin(0f);
		barcode.setRightMargin(0f);
		barcode.setTopMargin(0f);
		barcode.setBottomMargin(0f);
		// barcode image resolution in dpi
		barcode.setResolution(72);

		// disply human readable text under the barcode
		barcode.setShowText(true);
		// human reable text font style
		barcode.setTextFont(new Font("Arial", 0, 12));
		// ANGLE_0, ANGLE_90, ANGLE_180, ANGLE_270
		barcode.setRotate(Linear.ANGLE_0);

		try {
			return barcode.renderBarcode();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	} 
}
